﻿using System;
using DAL.Engine.Interface;
using DAL.Mongo.Interface;
using System.Linq;
using DAL.Engine.Domain;
using System.Collections.Generic;
using MongoDB.Driver.Builders;
using MongoDB.Driver.Linq;
using System.Linq.Expressions;

namespace DAL.Mongo.Repository
{
    public class UserRepository : MongoRepository<User, Guid>, IUserRepository
    {
        public UserRepository(IConfigurationManager configurationManager)
            : base(configurationManager)
        {
        }

        public void DeleteAll()
        {
            _collection.RemoveAll();
        }

        public IEnumerable<User> FilterBy(ISpecification<User> whereCriteria, int skip, int size)
        {
            if (whereCriteria == null)
                throw new ArgumentNullException("criteria");
            if (skip < 0)
                throw new ArgumentOutOfRangeException("skip");
            if (size <= 0)
                throw new ArgumentOutOfRangeException("size");

            return _collection.AsQueryable<User>()
                .Where(whereCriteria.IsSatisfiedBy)
                .Skip(skip)
                .Take(size);
        }
    }
}
